#ifndef DEVICESMEMHEAP_H_INCLUDED
#define DEVICESMEMHEAP_H_INCLUDED

#include "stdint.h"


/* 字节对齐（至少要4字节对齐） */
#define MEM_HEAP_ROUNDUP_VALUE   8
/* 使x对n字节对齐 */
#define memHeapRoundUp(x, n) (((x) + (n) - 1) & (~((n) - 1)))

/* 此区域内存未使用 */
#define MEM_UNUSED  0
/* 此区域内存已使用 */
#define MEM_USED    1


/* 模拟动态内存大小 */
#define DEVICES_MEM_LENGTH          (128 * 1)


typedef struct{
    int32_t startAddr: 30;
    int32_t stopAddr: 30;
    uint32_t state: 2;
}MemType;


/* 动态内存头部信息 */
extern MemType g_typeMemHeapHead;


void vMemHeapInit(void);
void vMemHeapCreate(MemType *ptypeMemHanle, uint8_t *pucMemHeap, int32_t iLength);
void *pvMemHeapMalloc(MemType *ptypeMemHanle, int32_t iSize);
void *pvMemHeapCalloc(MemType *ptypeMemHanle, int32_t iNumber, int32_t iSize);
void *pvMemHeapRealloc(MemType *ptypeMemHanle, void *pvMemAddr, int32_t iSize);
void vMemHeapFree(MemType *ptypeMemHanle, void *pvMemAddr);

#endif // DEVICESMEM_H_INCLUDED
